<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/FCKeditor.tld" prefix="FCK" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<c:set var="table" value="${param.table}"/>
<c:set var="formSessionName" value="form_${table}"/>
<c:set var="tableSessionName" value="table_${table}"/>
<!--取出FORM对象-->
<c:set var="form" value="${sessionScope[formSessionName]}"/>
<%
String tb = request.getParameter("table");
String tableDefault = tb + "_default";
String tableTether = tb + "_tether";
String defaultV = request.getParameter("default");
String tetherV = request.getParameter("tether");

if(defaultV != null && !defaultV.equals((String)session.getAttribute(tableDefault))){
	session.setAttribute(tableDefault,defaultV);
}
if(tetherV != null && !tetherV.equals((String)session.getAttribute(tableTether))){
	session.setAttribute(tableTether,tetherV);
}

String formaction = request.getParameter("do");
String sessionAction = tb + "_action";
if(formaction == null && session.getAttribute(sessionAction) == null){
	formaction = "dataOperateAction.do";
}else if(session.getAttribute(sessionAction) != null){
	formaction = (String)session.getAttribute(sessionAction);
}
session.setAttribute(sessionAction,formaction);
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>表　${table}　数据录入页面</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <link rel="StyleSheet" href="resource/css/default.css" type="text/css"/>
    <style type="text/css">
    body{
			background-color: #F9F8E8;
			font-family: arial;
			font-size: 12px;
		}
    </style>
  </head>
  <script language="javascript">
  //这个方法专为site_map表的操作而写
  function refer_type_change(sele){
  	var v = sele.value;
  	if(v == 1){
  		document.f_site_map.range_mode.disabled = true;
  		document.f_site_map.disp_amount.disabled = true;
  	}else if(v == 2){
  		document.f_site_map.range_mode.disabled = false;
  		document.f_site_map.disp_amount.disabled = false;
  	}
  }
  
  </script>
  <script type="text/javascript" src="FCKeditor/fckeditor.js"></script>
  <script type="text/javascript" src="resource/js/validation/validation.js"></script>
  <script type="text/javascript" src="resource/js/validation/form.js"></script>
  <body>
  	<FORM name="command" action="getAttributeAction.do" method="post">
	  	<INPUT type="hidden" name="action" value=""/>
	  	<INPUT type="hidden" name="table" value="${table}"/>
  	</FORM>
    <b>表&nbsp;${table}&nbsp;维护页</b><span style="padding-left:50px"><font color="#700700">${message }</font> <font color="red"> ${err_msg}</font></span>
    <!--如果没有，取得这个表的属性 -->
    <c:if test="${empty form}" var ="noForm">
	    <script language="javascript">
  			document.command.submit();
	    </script>
    </c:if>
    <c:if test = "${!noForm}">
    <c:set var = "rowNum" value = "${form.rowNum}"/>
    <!-- 显示表属性，并且以表单形式呈现 -->
    <FORM name="${form.formName}" method= "${form.method}" action="<%= formaction%>">
    	<INPUT type="hidden" name="table" value="${table}" /> 
	    <TABLE width="100%">
	    <c:set var="posi" value="${-1}"></c:set>
    	<c:forEach var="formElement"  items="${form.formList}" varStatus="status">
    		<c:if test="${formElement.htmlType != 'hidden'}" var = "hiddenCndi" scope="page">
    			<c:set var="posi" value="${posi + 1}"></c:set>
    		</c:if>
    		<c:if test="${hiddenCndi && posi % rowNum == 0}">
    		<tr>
    		</c:if>
    		<c:if test="${!hiddenCndi}"><input type = "${formElement.htmlType}" name="${formElement.fieldName}" value="${formElement.defaultValue}" 

size="${formElement.size}"/></c:if>
    		<c:if test="${hiddenCndi && formElement.htmlType != 'select' && formElement.htmlType != 'textarea' && formElement.htmlType != 'fckeditor'}">
	    		<td>${formElement.dispText}</td>
	    		<TD><input type = "${formElement.htmlType}" name="${formElement.fieldName}" value="${formElement.defaultValue}" 

size="${formElement.size}" onblur="validElement(this,'${formElement.validateString}','','${formElement.commnet}')" <c:if test="${formElement.disabled != false}"> readonly="readonly" </c:if> /></TD>
    		</c:if>
	    		<c:if test = "${formElement.htmlType == 'select'}">
	    			<td>${formElement.dispText}</td>
	    			<td>
	    			<SELECT name="${formElement.fieldName}" value="${formElement.defaultValue}" <c:if test="${formElement.onchange != 

null}">onchange = "${formElement.onchange}"</c:if> onblur="validElement(this,'${formElement.validateString}','','${formElement.commnet}')">
	    				<option value="">未选择</option>
	    				<c:forEach var="option" items="${formElement.dispList}">
	    					<option value="${option.value}">${option.dispText}</option>
	    				</c:forEach>
	    			</SELECT>
	    			</td>
	    		</c:if>
	    		<c:if test = "${formElement.htmlType == 'textarea'}">
	    			<td>${formElement.dispText}</td>
	    			<td>
	    			<textarea name="${formElement.fieldName}" rows="${formElement.rows}" cols="${formElement.cols}" onblur="validElement(this,'${formElement.validateString}','','${formElement.commnet}')"></textarea>
	    			</td>
	    		</c:if>
	    		<c:if test = "${formElement.htmlType == 'fckeditor'}">
	    			<c:if test="${posi%rowNum == 0}"><td></td></tr><tr>
	    			</c:if>
	    			<c:if test="${posi%rowNum == 1}"></tr>
		    			<tr>
	    			</c:if>
	    			<td>${formElement.dispText}</td>
	    			<td colspan="3">
	    			<textarea id="${formElement.fieldName}" name="${formElement.fieldName}" cols="${formElement.cols}" 

rows="${formElement.rows}"></textarea>
						<script type="text/javascript">
						 var oFCKeditor = new FCKeditor('${formElement.fieldName}') ;
						 oFCKeditor.BasePath = 'FCKeditor/';
						 oFCKeditor.ToolbarSet = "Basic" ;
						 oFCKeditor.Height = ${formElement.rows};
						 oFCKeditor.Width = ${formElement.cols};
						 //oFCKeditor.ToolbarSet = "Gk" ; 
						 oFCKeditor.ReplaceTextarea();
						</script>
	    			</td>
	    			<c:if test="${posi % rowNum == 0}">
	    				</tr><tr>
	    			</c:if>
	    		</c:if>
	    	<c:if test="${hiddenCndi && posi % rowNum == 1}">
    			</tr>
    		</c:if>
    	</c:forEach>
	<!-- 操作按纽 -->
	<tr>
    <td>
      <input type="button" onclick="addRecord();" value="新增" id="but_inse"/>
    </td>
    <td colspan="3">
      <input type="button" onclick="operateForm('query');" value="查询" id="but_quer"/>
      <input type="button" onclick="operateForm('update');" value="保存" id="but_upda"/>
      <input type="button" onclick="operateForm('delete');" value="删除" id="but_dele"/>
    </td>
  </tr>
  <tr><td colspan="4"><span id="err_msg_span"></span><input type="hidden" name="errorMsgSpan" value="err_msg_span"></td></tr>
	    </TABLE>
    </FORM>
    </c:if>
    <hr>
    
    <!-- 显示结果集 -->
    <!--取出Table对象-->
    <c:set var="table" value="${requestScope[tableSessionName]}"/>
    <c:set var="noData" value="${empty table}"/>
    <c:if test="${!noData}">
    <!-- 显示表头 --><!-- 显示表体 -->
    <div style="width:'3000';height:300;overflow-x:scroll;overflow-y:scroll">
    <TABLE id = "${table.tableId}">
    	<tr>
	    	<c:forEach var="valueDisp" items="${table.th}">
	    		<td id = "${valueDisp.name}">${valueDisp.dispText}</td>
	    	</c:forEach>
    	</tr>
    	<c:forEach var="row" items="${table.rows}">
    		<tr onclick="copy(this,false)" onmousemove="mOvr(this)" onmouseout="mOut(this)">
    		<c:forEach var="element" items="${row}">
    			<c:if test="${element.name != null && (element.name == 'hiddendiv' || element.name == 'hidden')}" var="hid">
    				<c:if test="${element.name == 'hiddendiv'}">
    					<TD><div style="display:none">${element.value}</div></TD>
    				</c:if>
    				<c:if test="${element.name == 'hidden'}">
    					<TD>idd<pre style="display:none">${element.value}</pre></TD>
    				</c:if>
    			</c:if>
    			<c:if test="${!hid}">
    				<TD>${element.value}</TD>
    			</c:if>
    		</c:forEach>
    		</tr>
    	</c:forEach>
    </TABLE>
    </div>
    </c:if>
  </body>
<script type="text/javascript" src="cep/js/easymana_1.js"></script>
<script type="text/javascript" src="cep/js/easymana_copy.js"></script>
<script language="javascript">
	setTableId("t_${table}");
	setFormName("${form.formName}");
</script>
</html>